
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.DistributionOrder;
import com.shop.cloud.mall.admin.service.DistributionOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 分销订单
 *
 * @author
 * @date 2021-04-30 10:26:30
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/distributionorder")
@Tag(description = "distributionorder", name = "分销订单管理")
public class DistributionOrderController {

    private final DistributionOrderService distributionOrderService;

    /**
     * 分销订单分页列表
     * @param page 分页对象
     * @param distributionOrder 分销订单
     * @return
     */
    @Operation(summary = "分销订单分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:distributionorder:index','mall:distributionuser:index')")
    public R getPage(Page page, DistributionOrder distributionOrder) {
        return R.ok(distributionOrderService.page1(page, distributionOrder));
    }

    /**
     * 分销订单查询
     * @param id
     * @return R
     */
    @Operation(summary = "分销订单查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:distributionorder:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(distributionOrderService.getById(id));
    }

    /**
     * 分销订单新增
     * @param distributionOrder 分销订单
     * @return R
     */
    @Operation(summary = "分销订单新增")
    @SysLog("新增分销订单")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:distributionorder:add')")
    public R save(@RequestBody DistributionOrder distributionOrder) {
        return R.ok(distributionOrderService.save(distributionOrder));
    }

    /**
     * 分销订单修改
     * @param distributionOrder 分销订单
     * @return R
     */
    @Operation(summary = "分销订单修改")
    @SysLog("修改分销订单")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:distributionorder:edit','mall:distributionuser:get')")
    public R updateById(@RequestBody DistributionOrder distributionOrder) {
        return R.ok(distributionOrderService.updateById(distributionOrder));
    }

    /**
     * 分销订单删除
     * @param id
     * @return R
     */
    @Operation(summary = "分销订单删除")
    @SysLog("删除分销订单")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:distributionorder:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(distributionOrderService.removeById(id));
    }

}
